-
Notifications
You must be signed in to change notification settings - Fork 1.8k
cast_possible_truncation: Support size_of
, align_of
, and size_of_val
#15488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
cast_possible_truncation: Support size_of
, align_of
, and size_of_val
#15488
Conversation
Lintcheck changes for c5a67a8
This comment will be updated if you push new changes |
☔ The latest upstream changes (possibly e9b7045) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great contribution! Sorry for the late review, I've been very busy this past two weeks.
ExprKind::Call(callee, [_]) => match self.get_fn_diagnostic_name(callee) { | ||
// `align_of_val` doesn't have a diagnostic name, unfortunately. | ||
// Some(sym::mem_align_of_val) => self.align_of_call(callee), | ||
Some(sym::mem_size_of_val) => self.size_of_call(callee), | ||
_ => None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the other comment
ExprKind::Call(callee, [_]) => match self.get_fn_diagnostic_name(callee) { | |
// `align_of_val` doesn't have a diagnostic name, unfortunately. | |
// Some(sym::mem_align_of_val) => self.align_of_call(callee), | |
Some(sym::mem_size_of_val) => self.size_of_call(callee), | |
_ => None, |
ExprKind::Call(callee, []) => match self.get_fn_diagnostic_name(callee) { | ||
Some(sym::i8_legacy_fn_max_value) => Some(Constant::Int(i8::MAX as u128)), | ||
Some(sym::i16_legacy_fn_max_value) => Some(Constant::Int(i16::MAX as u128)), | ||
Some(sym::i32_legacy_fn_max_value) => Some(Constant::Int(i32::MAX as u128)), | ||
Some(sym::i64_legacy_fn_max_value) => Some(Constant::Int(i64::MAX as u128)), | ||
Some(sym::i128_legacy_fn_max_value) => Some(Constant::Int(i128::MAX as u128)), | ||
Some(sym::mem_align_of) => self.align_of_call(callee), | ||
Some(sym::mem_size_of) => self.size_of_call(callee), | ||
_ => None, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[..]
The rest pattern also allows for zero-sized arrays, no need for the extra branch.
ExprKind::Call(callee, []) => match self.get_fn_diagnostic_name(callee) { | |
Some(sym::i8_legacy_fn_max_value) => Some(Constant::Int(i8::MAX as u128)), | |
Some(sym::i16_legacy_fn_max_value) => Some(Constant::Int(i16::MAX as u128)), | |
Some(sym::i32_legacy_fn_max_value) => Some(Constant::Int(i32::MAX as u128)), | |
Some(sym::i64_legacy_fn_max_value) => Some(Constant::Int(i64::MAX as u128)), | |
Some(sym::i128_legacy_fn_max_value) => Some(Constant::Int(i128::MAX as u128)), | |
Some(sym::mem_align_of) => self.align_of_call(callee), | |
Some(sym::mem_size_of) => self.size_of_call(callee), | |
_ => None, | |
}, | |
ExprKind::Call(callee, [..]) => match self.get_fn_diagnostic_name(callee) { | |
Some(sym::i8_legacy_fn_max_value) => Some(Constant::Int(i8::MAX as u128)), | |
Some(sym::i16_legacy_fn_max_value) => Some(Constant::Int(i16::MAX as u128)), | |
Some(sym::i32_legacy_fn_max_value) => Some(Constant::Int(i32::MAX as u128)), | |
Some(sym::i64_legacy_fn_max_value) => Some(Constant::Int(i64::MAX as u128)), | |
Some(sym::i128_legacy_fn_max_value) => Some(Constant::Int(i128::MAX as u128)), | |
Some(sym::mem_align_of) => self.align_of_call(callee), | |
Some(sym::mem_size_of) | Some(sym::mem_size_of_val)=> self.size_of_call(callee), | |
_ => None, | |
}, |
} | ||
} | ||
|
||
fn align_of_call(&self, callee: &Expr<'_>) -> Option<Constant<'tcx>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add some documentation here for these two functions?
ping @RunDevelopment 🏓 I'm not sure if you saw my review or if it just flew under the radar? |
fixes parts of #9613, related to #12962
Unlike #12962, I added support for
size_of
,align_of
, andsize_of_val
toConstEval
, so all lints using it benefit from this change.cast_possible_truncation
itself changed relatively little. Functions calls are now delegated to const eval and ptr-sized to fixed-sized casts now considerfrom_nbits
.changelog: [
cast_possible_truncation
]: supportsize_of
,align_of
, andsize_of_val
My intention with this PR is not to superceed #12962, but to get in a simple improvement while I work on #15342.